import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const state = {
  //分类
  classList:[],
  noteList:[],
  curNote:{},
  curClass:{},
  isEditor:false,
  alertMsg:'',
  alertState:false,
  maxEditor:true,
  curIndex:'',
};

const mutations = {
  SET_NOTE_LIST (state , list) {
    state.noteList = list;
  },
  ALL_CLASS (state , list) {
    state.classList = list;
  },
  ADD_CLASS (state , data) {
    state.classList.push(data);
  },
  DEL_CLASS (state , index) {
    state.classList.splice(index,1);
  },
  CUR_CLASS (state , index) {
    state.curClass = state.classList[index];
  },
  //改变状态
  EDITOR (state , sta) {
    state.isEditor = sta;
  },
  //当前note
  CUR_NOTE (state , index) {
    state.isEditor = false;
    state.curIndex = index;
    state.curNote = state.noteList[index] || [];
  },
  SHOW_MSG (state , msg) {
    state.alertMsg = msg;
    state.alertState = true;
    setTimeout(() => {
      state.alertState = false;
    } , 1500);
  },
  TOGGLE_V (state , _state) {
    state.maxEditor = _state;
  },
  //删除笔记
  DEL_NOTE (state , index) {
    state.noteList.splice(index , 1);
  }
};

export default new Vuex.Store({
    state,
    mutations
});
